package com.site.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.site.blog.dao.WebLogMapper;
import com.site.blog.entity.log.WebLog;
import com.site.blog.service.LogService;
import org.springframework.stereotype.Service;


/**
 * @author : Connor-G 康纳-郭
 * @date : 19:04 20.12.20
 * @Company : http://www.zzrgsoft.org
 * @Version : 1.0
 */

@Service
public class LogServiceImpl extends ServiceImpl<WebLogMapper, WebLog> implements LogService {

    @Override
    public int addLog(WebLog log) {
        return baseMapper.insertWebLog(log);
    }

    @Override
    public Page selectListPage(Integer pageNum, Integer pageSize, WebLog webLog) {

        Page<WebLog> page = new Page<>(pageNum, pageSize);

        QueryWrapper<WebLog> webLogQueryWrapper = new QueryWrapper<>();
        if (webLog.getMethodType() != null) {
            webLogQueryWrapper.lambda().eq(true, WebLog::getMethodType, webLog.getMethodType());
        }
        webLogQueryWrapper.lambda().orderByDesc(WebLog::getGmtCreate);
        baseMapper.selectPage(page, webLogQueryWrapper);

        return page;
    }
}
